package com.kingmed.kmss.framework.feign.client.admin;

import com.kingmed.kmss.common.dto.admin.sys.SysMsgCreateDTO;
import com.kingmed.kmss.common.dto.admin.sys.SysMsgDTO;
import com.kingmed.kmss.common.dto.admin.ums.*;
import com.kingmed.kmss.common.qc.admin.AdminQC;
import com.kingmed.kmss.common.vo.CommonResponse;
import com.kingmed.kmss.common.vo.admin.SysBpmnConfigVO;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

@FeignClient(value = "kmss-admin", url = "${internalService.adminService.url}", contextId = "common-admin-interface", fallback = CommonAdminFeignFallbackService.class)
public interface CommonAdminFeignService {

    /**
     * 获取本部门及下属所有部门（有parent关系的所有子部门）
     *
     * @param orgId
     * @return
     */
    @GetMapping(value = "/admin/ext/ums/getOrgAndChild")
    String getOrgAndChild(@RequestParam(name = "orgId") Long orgId);

    /**
     * 用户ID查上级组织部门信息
     *
     * @param adminId
     * @return
     */
    @GetMapping(value = "/admin/ums/organization/getParentUpByAdminId")
    CommonResponse<List<OrganizationDTO>> getParentUpByAdminId(@RequestParam("adminId") Long adminId);

    @GetMapping(value = "/admin/ums/user/getByUsername")
    CommonResponse<AdminDTO> getByUsername(@RequestParam(name = "username") String username);


    /**
     * 根据用户名列表获取员工列表
     */
    @PostMapping(value = "/admin/ums/user/listByUsername")
    CommonResponse<List<AdminDTO>> listByUsername(@RequestBody List<String> usernameList);

    // 列表查询
    @PostMapping(value = "/admin/ums/group/relation/list")
    public CommonResponse<List<BpmnMembershipDTO>> queryList(@RequestBody BpmnQueryDTO queryQc);

    @PostMapping(value = "/admin/ext/ums/queryByCondition")
    CommonResponse<List<AdminDTO>> queryByCondition(@RequestBody AdminQC userQC);

    /**
     * 查询用户详情
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/admin/ums/user/get/{id}")
    CommonResponse<AdminDTO> loadById(@PathVariable(value = "id") Long id);

    /**
     * 根据组织ID获取组织详细信息
     */
    @GetMapping(value = "/admin/ext/ums/queryOrgById")
    OrganizationDTO queryOrgById(@RequestParam("orgId") Long orgId);

    /**
     * 获取所属集团、大区、子公司平铺ByAdminID
     *
     * @param adminId
     * @return
     */
    @GetMapping(value = "/admin/ums/organization/getGroupRegionBranchByAdminId")
    CommonResponse<OrganizationTileDTO> getGroupRegionBranchByAdminId(@RequestParam Long adminId);

    /**
     * KMCS子公司名称及代码详情
     */
    @GetMapping(value = "/admin/ums/kmcs/org/detail")
    CommonResponse<UmsKmcsOrgDTO> kmcsOrgDetail(@RequestParam String orgId);

    /**
     * KMCS子公司名称及代码列表
     */
    @GetMapping(value = "/admin/ums/kmcs/org/list")
    CommonResponse<List<UmsKmcsOrgDTO>> kmcsOrgList(@RequestParam(required = false) Integer level);

    // 根据用户ID批量查用户
    @PostMapping(value = "/admin/ums/user/queryBatchByAdminId")
    @ResponseBody
    CommonResponse<List<AdminDTO>> queryBatchByEmployee(@RequestBody List<String> adminIdList);

    /**
     * 只查员工信息，不附带任何其它信息
     */
    @PostMapping(value = "/admin/ums/user/queryBatchByAdminIdList")
    @ResponseBody
    CommonResponse<List<AdminDTO>> queryBatchByAdminIdList(@RequestBody List<String> adminIdList);

    /**
     * 创建系统消息
     */
    @PostMapping(value = "/admin/sys/msg/create")
    CommonResponse<Boolean> createMsg(@RequestBody @Valid SysMsgCreateDTO sysMsgDTO);

    // 设置消息为已读-按业务条件
    @PostMapping(value = "/admin/sys/msg/markAsReadForBusiness")
    CommonResponse<Boolean> markMsgAsReadForBusiness(@RequestBody @Valid SysMsgDTO sysMsgDTO);

    /**
     * 批量创建系统消息
     *
     * @param sysMsgList
     * @return
     */
    @PostMapping(value = "/admin/sys/msg/createBatch")
    CommonResponse<Boolean> createBatchMsg(@RequestBody @Valid List<SysMsgCreateDTO> sysMsgList);

    /**
     * 根据用户名，员工号，姓名模糊查询
     */
    @GetMapping(value = "/admin/ums/user/fuzzyQueryAllByName")
    CommonResponse<List<AdminDTO>> fuzzyQueryAllByName(@RequestParam String username);

    /**
     * 根据用户ID查询
     */
    @GetMapping(value = "/admin/ext/ums/getUserById")
    CommonResponse<AdminDTO> getUserById(@RequestParam String id);

    /**
     * 组织ID获取全部子公司：有权限看到的所有子公司
     *
     * @param orgId
     * @return
     */
    @GetMapping(value = "/admin/ums/organization/getBranchesByOrgId")
    CommonResponse<List<OrganizationDTO>> getBranchesByOrgId(@RequestParam("orgId") Long orgId);

    /**
     * 根据adminId获取全部子公司：有权限看到的所有子公司
     *
     * @param adminId
     * @return
     */
    @GetMapping(value = "/admin/ums/organization/getBranchesByAdminId")
    CommonResponse<List<OrganizationDTO>> getBranchesByAdminId(@RequestParam("adminId") Long adminId);

    /**
     * 通过子公司名称查询子公司信息, 通过大区名称查询大区信息
     */
    @GetMapping(value = "admin/ums/organization/getOrgByName")
    CommonResponse<List<OrganizationDTO>> getOrgByName(@RequestParam(value = "branchName", required = false) String branchName,
                                                       @RequestParam(value = "regionName", required = false) String regionName);

    /**
     * 外部调用-根据员工号获取相关的信息（角色权限），用于对外接口的数据权限控制
     *
     * @param adminLoginDto
     * @return
     */
    @PostMapping(value = "/admin/ext/ums/loadAdminAuthDtoByUsernameNew")
    CommonResponse<AdminAuthDTO> loadAdminAuthDtoByUsernameNew(@RequestBody AdminLoginDTO adminLoginDto);

    /**
     * 根据orgId获取子公司信息(orgId必须是子公司之下的组织或者部门)
     *
     * @param orgId
     * @return
     */
    @GetMapping(value = "/admin/ums/organization/getBranch")
    CommonResponse<OrganizationDTO> getBranch(@RequestParam Long orgId);

    /**
     * 根据orgIds批量获取子公司信息
     *
     * @param orgIds
     * @return
     */
    @GetMapping(value = "/admin/remote/getOrgByIds")
    CommonResponse<Map<Long, OrganizationDTO>> getOrgByIds(@RequestBody List<Long> orgIds);

    /**
     * 根据所属子公司id获取所属大区
     *
     * @param branchId
     * @return
     */
    @GetMapping(value = "/admin/remote/getRegionByBranchId")
    CommonResponse<OrganizationDTO> getRegionByBranchId(@RequestParam("branchId") Long branchId);

    /**
     * 获取所有大区
     *
     * @return
     */
    @GetMapping(value = "/admin/ums/organization/getRegions")
    CommonResponse<List<OrganizationDTO>> getRegions();

    /**
     * 获取所有子公司
     *
     * @return
     */
    @ApiOperation("获取所有子公司")
    @GetMapping(value = "/admin/ums/organization/getAllBranch")
    CommonResponse<List<OrganizationDTO>> getAllBranch();

    @ApiOperation("生成流水号")
    @GetMapping("/admin/sys/seq/genNextVal")
    CommonResponse<String> genNextVal(@RequestParam("bizKey") @ApiParam(value = "业务编码", required = true) String bizKey,
                                      @RequestParam(value = "len", required = false, defaultValue = "1") @ApiParam(value = "序号长度") Integer len,
                                      @RequestParam(value = "step", required = false, defaultValue = "1") @ApiParam(value = "步长") Integer step);


    /**
     * 根据level获取组织列表
     * @param levels
     * @return
     */
    @PostMapping(value = "/admin/ums/kmcs/org/listByLevels")
    CommonResponse<List<UmsKmcsOrgDTO>> listByLevels(@RequestBody List<Integer> levels);


    /**
     * 根据员工工号列表获取员工列表
     * @param employeeNumList
     * @return
     */
    @PostMapping(value = "/admin/ext/ums/listEmployeeNum")
    CommonResponse<List<AdminDTO>> listEmployeeNum(@RequestBody List<String> employeeNumList);

    /**
     * 根据公司id获取流程审批配置
     */
    @ApiOperation("获取子公司配置")
    @GetMapping("/admin/sys/config/bpmn/getByCompanyIdWithDefault")
    CommonResponse<SysBpmnConfigVO> getBpmnConfigByCompanyId(@RequestParam @ApiParam(value = "公司id",required = true) Long companyId);

}
